package com.chengxiaoxiao.service.impl;

import com.chengxiaoxiao.commons.Page;
import com.chengxiaoxiao.dao.ReturnsDao;
import com.chengxiaoxiao.dao.impl.ReturnsDaoImpl;
import com.chengxiaoxiao.domain.Returns;
import com.chengxiaoxiao.service.ReturnsService;

import java.util.List;

public class ReturnsServiceImpl implements ReturnsService {
    private ReturnsDao dao = new ReturnsDaoImpl();

    @Override
    public void add(Returns returns) {
        dao.add(returns);
    }

    @Override
    public void update(Returns returns) {
        dao.update(returns);
    }

    @Override
    public void delete(long id) {
        dao.delete(id);
    }

    @Override
    public List get() {
        return dao.get();
    }

    @Override
    public Returns getbyId(long id) {
        return dao.getbyId(id);
    }

    @Override
    public Page getListPage(String num) {
        int pageNum = 1;
        if (null != num && num != "") {
            pageNum = Integer.parseInt(num);
        }

        int total = dao.getTotalRecordsNum();
        Page page = new Page(pageNum, total);
        List<Returns> list = dao.getListPage(page.getStartIndex(), page.getPageSize());

        page.setRecords(list);

        return page;
    }
}
